<?php
namespace app\index\controller;

class Index extends Common
{
    public function index()
    {
        $products=db('product')->field('a.*')->alias('a')->where('rec=1')->order('a.id desc')->paginate(100);
        $this->assign('products',$products);
        
       //货源分类列表展示

       $procates=db('procate')->where(array('pid'=>0))->order('sort DESC')->select();
        foreach ($procates as $k => $v) {
            $children=db('product')->where(array('cateid'=>$v['id']))->order("time DESC limit 10")->select();
            if($children){
                $procates[$k]['childrens']=$children;
            }else{
                $procates[$k]['childrens']=0;
            }
        }
       //货源分类列表展示



        //新闻分类列表展示
             $cates=db('cate')->where(array('pid'=>0))->order('sort DESC')->select();
        foreach ($cates as $k => $v) {
            $children=db('article')->where(array('cateid'=>$v['id']))->order("time DESC limit 10")->select();
            if($children){
                $cates[$k]['childrens']=$children;
            }else{
                $cates[$k]['childrens']=0;
            }
        }
       //货

        //新闻分类列表展示
       // print_r($procates);
        $hotones=db('product')->where(array('zan'=>1))->order('click DESC')->select();
        $hottwos=db('product')->where(array('zan'=>2))->order('click DESC')->select();
        $hotthrees=db('product')->where(array('zan'=>3))->order('click DESC')->select();
        $hotfours=db('product')->where(array('zan'=>4))->order('click DESC')->select();
        $this->assign('hotones',$hotones);
         $this->assign('hottwos',$hottwos);
          $this->assign('hotthrees',$hotthrees);
           $this->assign('hotfours',$hotfours);




        $this->assign("procates",$procates);
        $this->assign("cates",$cates);
        return view();
    }
}
